/**
 * @author wangdx
 * @since 2025/8/1
 */
import java.util.Random;
import java.util.Scanner;

/**
 * 猜数字游戏
 */
public class GuessingGame {
    public static void main(String[] args) {
        // 生成 1 到 100 之间的随机数
        Random random = new Random();
        int secretNumber = random.nextInt(100) + 1;
        Scanner scanner = new Scanner(System.in);
        int guess;
        int attempts = 0;

        System.out.println("欢迎来到猜数字游戏！我已经想好了一个 1 到 100 之间的整数，你可以开始猜啦。");

        do {
            System.out.print("请输入你的猜测：");
            guess = scanner.nextInt();
            attempts++;

            if (guess < secretNumber) {
                System.out.println("猜的数字太小啦，再往大了试试！");
            } else if (guess > secretNumber) {
                System.out.println("猜的数字太大啦，再往小了试试！");
            } else {
                System.out.println("恭喜你，猜对啦！你一共用了 " + attempts + " 次尝试。");
            }
        } while (guess != secretNumber);

        scanner.close();
    }
}